package core.util;

import java.util.HashMap;

/**
 * @author songduk park
 * 
 */
public class StringHashMap extends HashMap<String, Object> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Object put(String key, Object value) {
		String newKey = key.toLowerCase();

		if (value == null)
			return super.put(newKey, "");
		return super.put(newKey, value);
	}

	public Object get(String key) {
		return super.get(key.toLowerCase());
	}

	public int getIntValue(String key) {
		Object obj = get(key);

		if (obj == null)
			return 0;
		else if (obj instanceof Integer)
			return (Integer) obj;
		else
			return StringUtil.getInteger(obj.toString());
	}

	public Object getNullExcept(String key) {
		Object obj = super.get(key.toLowerCase());

		if (obj == null)
			return "";
		else
			return obj;
	}

	public Object getNullExcept(String key, Object alternative) {
		Object obj = super.get(key.toLowerCase());

		if (obj == null)
			return alternative;
		else
			return obj;
	}
}
